//
//  MTWithdrawBindAccountAlertView.swift
//  MT
//
//  Created by 陈悦 on 2020/5/26.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit

class MTWithdrawBindAccountAlertView: UIView {
    
    /// 完成闭包
    var completionHandler: ((Int)->())?
    
    var model: MineWithdrawModel? {
        didSet {
            guard let model = model else { return }
            bankAccountLab.text = model.bankStatus ? model.bankAccount?.account : ""
            aliAccountLab.text = model.aliStatus ? model.aliAccount?.account : ""
        }
    }
    
    @IBOutlet weak var bgViewHeight: NSLayoutConstraint!
    @IBOutlet var contentView: UIView!
    @IBOutlet weak var bankAccountLab: UILabel!
    @IBOutlet weak var aliAccountLab: UILabel!
    
    @IBAction func closeView(_ sender: Any) {
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 0
        }) { (flag) in
            self.removeFromSuperview()
        }
    }
    
    @IBAction func onBankBtnClick(_ sender: Any) {
        if let completionHandler = completionHandler {
            completionHandler(2)
        }
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 0
        }) { (flag) in
            self.removeFromSuperview()
        }
    }
    @IBAction func onAlipayBtnClicked(_ sender: Any) {
        if let completionHandler = completionHandler {
            completionHandler(1)
        }
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 0
        }) { (flag) in
            self.removeFromSuperview()
        }
        
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        // 加载xib
        contentView = (Bundle.main.loadNibNamed("MTWithdrawBindAccountAlertView", owner: self, options: nil)?.last as! UIView)
        // 设置frame
        contentView.frame = frame
        contentView.backgroundColor = UIColor.black.withAlphaComponent(0.5)
        //        NSToolObjectClass.animationWithAlertViewWithView(allView: tipView)
        
//        bgView.layer.cornerRadius = 8
//
//        closeBtn.layer.cornerRadius = 20
//        closeBtn.layer.borderWidth = 1
//        closeBtn.layer.borderColor = UIColor.text.x1d1a1a.cgColor
//        checkoutBtn.layer.cornerRadius = 20
        bgViewHeight.constant = 143+ScreenBottomExtraOffset
        // 添加上去
        addSubview(contentView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
